package beanstao.util.socket;

import beanstao.util.services.AbstractService;
import beanstao.util.services.ServiceType;

/**
 * 针对 Socket 的管理理实现的简单超类。
 */
public abstract class AbstractSocketService extends AbstractService
{

	protected final int port;

	protected final String serviceName;

	protected final boolean enableJmx;

	public AbstractSocketService(ServiceType type, int port, String serviceName)
	{
		super(type);
		this.port = port;
		this.serviceName = serviceName;
		this.enableJmx = false;
	}

	public AbstractSocketService(ServiceType type, int port, String serviceName, boolean enableJmx)
	{
		super(type);
		this.port = port;
		this.serviceName = serviceName;
		this.enableJmx = enableJmx;
	}

	/**
	 * @return 端口号
	 */
	public final int getPort()
	{
		return this.port;
	}

	/**
	 * 返回当前实例的状态管理
	 * 
	 * @return StatusManager
	 */
	public abstract StatusManager getStatusManager();

	/**
	 * If JMX is enabled, will register the given object under the service name with which this class was created.
	 * 
	 * @param obj
	 *            Object to register as an MBean
	 */
	@Deprecated
	protected void enableJmx(Object obj)
	{
		// if (this.enableJmx)
		// {
		// JmxUtils.registerMbean(this.serviceName, obj);
		// }
	}

}
